<script lang="ts" setup>
import axios from 'axios'
import {ElMessage} from 'element-plus'
//默认配置
axios.defaults.baseURL = 'http://192.168.3.85:8080/'
axios.defaults.timeout = 5000
axios.defaults.headers['token'] = localStorage.getItem('token')
axios.defaults.headers['token'] = '123456789'

const get = async (url: string, params: any) => {
  return axios.get(url, {params})
}

const get2 = async (url: string, params: any) => {
  return axios({
    url,
    method: 'GET',
    params,
  })
}

const del = async (url: string, params: any) => {
  return axios({
    url,
    method: 'DELETE',
    params,
  })
}

const post = async (url: string, data: any) => {
  return axios({
    url,
    method: 'POST',
    data,
  })
}

const put = async (url: string, data: any) => {
  return axios({
    url,
    method: 'PUT',
    data,
  })
}

const patch = async (url: string, data: any) => {
  return axios({
    url,
    method: 'PATCH',
    data,
  })
}
const getUser = async () => {
  try {
    const {data} = await get('login', {username: 'admin', password: '123456'})
    if (data.code === 200) {
      ElMessage.success(data.msg)
    }
  } catch (err) {
    ElMessage.error('网络请求错误')
  }
}
//引入useGlobelProperties.ts，并将方法useGlobelProperties 解析出来
import useGlobelProperties from './useGlobelProperties'

const that = useGlobelProperties()
console.log(that)
</script>
<template>
  <p>axios {{ axios.VERSION }} -- {{ $name }}</p>
  <p>{{ $name }} {{ age }} {{ $user }} {{ $user.name }}</p>
  <el-button type="primary" @click="getUser">axios get</el-button>
  <el-button type="primary" @click="$message.success('ok')">$message.success('ok')</el-button>
</template>
